<script setup>
import axios from 'axios'
import {ref} from "vue";

const options = ref({
  baseURL: 'https://jsonplaceholder.typicode.com',
  method: 'get',
  url: '',
  headers: {
    'Content-Type': 'application/json',
  },
  data: {},
  params: {},
})

const pageSettings = ref({
  activeName: 'params'
})

const sendRequest = () => {
  const instance = axios.create({
    baseURL: options.value.baseURL,
    method: options.value.method,
    headers: options.value.headers,
  })
  instance.request({
    method: options.value.method,
    url: options.value.url,
    headers: options.value.headers,
    data: options.value.data,
    params: options.value.params,
  })
}
</script>

<template>
  <div class="w-screen h-screen flex justify-center items-center p-10">
    <div class="w-full h-full flex justify-center">
      <div class="h-full flex-1">
        <el-row class="flex-1">
          <el-col :span="3">
            <el-select v-model="options.method">
              <el-option label="GET" value="get"/>
              <el-option label="POST" value="post"/>
              <el-option label="DELETE" value="delete"/>
              <el-option label="PUT" value="put"/>
            </el-select>
          </el-col>
          <el-col :span="18">
            <el-input placeholder="Enter URL" v-model="options.url">
              <template #prepend>{{ options.baseURL }}</template>
            </el-input>
          </el-col>
          <el-col :span="3">
            <el-button class="w-full" @click="sendRequest">Send</el-button>
          </el-col>
        </el-row>
        <div class="w-full mt-2">
          <el-tabs type="border-card" v-model="pageSettings.activeName">
            <el-tab-pane label="Params" name="params">
              <el-table :data="[{name: 'a', value: 'b'}]" border>
                <el-table-column label="参数名">
                  <template #default="scope">
                    <el-input></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="参数值">
                  <template #default="scope">
                    <el-input></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
            <el-tab-pane label="Body" name="body">Config</el-tab-pane>
            <el-tab-pane label="Headers" name="headers">Role</el-tab-pane>
          </el-tabs>
        </div>
      </div>
      <el-row class="flex-1">
        {{ options }}
        {{pageSettings}}
      </el-row>
    </div>
  </div>
</template>

<style scoped>

</style>
